home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / executor / ex_xdebug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  6.7 KB  |  311 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    ex_xdebug.c
  4.  *
  5.  *   DESCRIPTION
  6.  *    routines to graphically demonstrate query execution
  7.  *      (via communication with a separate X process)
  8.  *
  9.  *   INTERFACE ROUTINES
  10.  *    ExecXInitialize   - initialize the X interface process
  11.  *    ExecXNewTree      - initialize the tree
  12.  *    ExecXAddNode      - add a node to the tree
  13.  *    ExecXSignalNode   - send a message to a node in the tree
  14.  *    ExecXShowTree      - map the viewport holding the tree
  15.  *    ExecXHideTree      - unmap the viewport with the tree
  16.  *    ExecXTerminate      - shut down the X interface process
  17.  *
  18.  *    x_at_init      - hook to initialize the X process
  19.  *    x_post_init      - do nothing
  20.  *    x_pre_proc      \ hooks to highlight node being processed
  21.  *    x_post_proc      /
  22.  *    x_pre_end      - do nothing
  23.  *    x_post_end      - hook to terminate the X process
  24.  *
  25.  *    InitXHook      - function to initialize a hook full of
  26.  *                the above X debugging routines.
  27.  *
  28.  *   NOTES
  29.  *    This is a simple interface to an X program which
  30.  *    takes simple commands from its standard input and displays
  31.  *    the query tree interactively.  As the query is processed,
  32.  *    the nodes in the tree are visually updated so the user
  33.  *    sees the query execute.
  34.  *
  35.  *   IDENTIFICATION
  36.  *    $Header: /private/postgres/src/executor/RCS/ex_xdebug.c,v 1.3 1991/11/17 21:10:46 mer Exp $
  37.  * ----------------------------------------------------------------
  38.  */
  39.  
  40. #include "executor/executor.h"
  41.  RcsId("$Header: /private/postgres/src/executor/RCS/ex_xdebug.c,v 1.3 1991/11/17 21:10:46 mer Exp $");
  42.  
  43. /* ----------------
  44.  *    global vars, etc.
  45.  * ----------------
  46.  */
  47. bool ExecXInitialized = false;
  48.  
  49. char xexemon_buf[BUFSIZ];
  50. FILE *xexemon_fd;
  51. char *xexemon_path;
  52.  
  53. #define XEXEMON(x) \
  54.     fprintf(xexemon_fd, x)
  55.  
  56. #define NODE_ENTER 1
  57. #define NODE_LEAVE 2
  58.  
  59. /* ----------------------------------------------------------------
  60.  *             xexemon interface routines
  61.  * ----------------------------------------------------------------
  62.  */
  63.  
  64. /* ----------------
  65.  *    ExecXInitialize forks the xexemon process
  66.  * ----------------
  67.  */
  68. void
  69. ExecXInitialize()
  70. {
  71.     if (ExecXInitialized)
  72.     return;
  73.     
  74.     xexemon_path = (char *) getenv("PGXEXEMONPATH");
  75.     if (xexemon_path == NULL) {
  76.     xexemon_fd = (FILE *) NULL;
  77.     return;
  78.     }
  79.     
  80.     xexemon_fd = (FILE *) popen(xexemon_path, "w");
  81.  
  82.     /* ----------------
  83.      *    to delay while X process starts..
  84.      * ----------------
  85.      */
  86.     gets(xexemon_buf);
  87.     
  88.     ExecXInitialized = true;
  89. }
  90.  
  91. /* ----------------
  92.  *    ExecXNewTree
  93.  * ----------------
  94.  */
  95. void
  96. ExecXNewTree()
  97. {
  98.     if (xexemon_fd == NULL)
  99.     return;
  100.     XEXEMON("N;");
  101. }
  102.  
  103. /* ----------------
  104.  *    ExecXAddNode
  105.  * ----------------
  106.  */
  107. void
  108. ExecXAddNode(base_id, title, supernode_id)
  109.     int        base_id;
  110.     char     *title;
  111.     int     supernode_id;
  112. {
  113.     if (xexemon_fd == NULL)
  114.     return;
  115.  
  116.     sprintf(xexemon_buf, "A%d,%s,%d;", base_id, title, supernode_id);
  117.     XEXEMON(xexemon_buf);
  118. }
  119.  
  120. /* ----------------
  121.  *    ExecXSignalNode
  122.  * ----------------
  123.  */
  124. void
  125. ExecXSignalNode(base_id, signal)
  126.     int        base_id;
  127.     int        signal;
  128. {
  129.     if (xexemon_fd == NULL)
  130.     return;
  131.     
  132.     /* XEXEMON("Sname,code,parameters;"); */
  133.  
  134.     switch (signal) {
  135.     case NODE_ENTER:
  136.     sprintf(xexemon_buf, "S%d,B,3;", base_id);
  137.     break;
  138.  
  139.     case NODE_LEAVE:
  140.     sprintf(xexemon_buf, "S%d,B,1;", base_id);
  141.     break;
  142.  
  143.     default:
  144.     return;
  145.     }
  146.     
  147.     XEXEMON(xexemon_buf);
  148. }
  149.  
  150. /* ----------------
  151.  *    ExecXShowTree
  152.  * ----------------
  153.  */
  154. void
  155. ExecXShowTree()
  156. {
  157.     if (xexemon_fd == NULL)
  158.     return;
  159.     XEXEMON("M;");
  160. }
  161.  
  162. /* ----------------
  163.  *    ExecXHideTree
  164.  * ----------------
  165.  */
  166. void
  167. ExecXHideTree()
  168. {
  169.     if (xexemon_fd == NULL)
  170.     return;
  171.     XEXEMON("U;");
  172. }
  173.  
  174. /* ----------------
  175.  *    ExecXTerminate
  176.  * ----------------
  177.  */
  178. void
  179. ExecXTerminate()
  180. {
  181.     if (xexemon_fd == NULL)
  182.     return;
  183.     
  184.     XEXEMON("Q;");
  185.  
  186.     /* ----------------
  187.      *    reset the initialized flag and the file descriptor..
  188.      * ----------------
  189.      */
  190.     ExecXInitialized = false;
  191.     xexemon_fd = NULL;
  192. }
  193.  
  194. /* ----------------------------------------------------------------
  195.  *            X hook functions
  196.  * ----------------------------------------------------------------
  197.  */
  198.  
  199. void
  200. x_at_init(node, state)
  201.     Plan     node;        /* plan node */
  202.     BaseNode     state;        /* node's private state */
  203. {
  204.     int      base_id =     get_base_id(state);
  205.     Plan    base_parent =     (Plan) get_base_parent(state);
  206.     BaseNode     parentstate;        
  207.     int      parent_id;
  208.     
  209.     if (base_parent == NULL) {
  210.     ExecXInitialize();
  211.     parent_id = 0;
  212.     } else {
  213.     parentstate = (BaseNode) get_base_parent_state(state);
  214.     parent_id = get_base_id(parentstate);
  215.     }
  216.     
  217.     ExecXAddNode(base_id, (char *)GetNodeName((Node)node), parent_id);
  218. }
  219.     
  220. void
  221. x_post_init(node, state)
  222.     Plan node;            /* plan node */
  223.     BaseNode state;        /* node's private state */
  224. {
  225. }
  226.  
  227. void
  228. x_pre_proc(node, state)
  229.     Plan node;            /* plan node */
  230.     BaseNode state;        /* node's private state */
  231. {
  232.     int      base_id =     get_base_id(state);
  233.     Plan     base_parent =     (Plan) get_base_parent(state);
  234.     BaseNode     parentstate;        
  235.     int      parent_id;
  236.  
  237.     /* ----------------
  238.      *    "leave" the parent node and "enter" this node
  239.      * ----------------
  240.      */
  241.     if (base_parent != NULL) {
  242.     parentstate = (BaseNode) get_base_parent_state(state);
  243.     parent_id = get_base_id(parentstate);
  244.     ExecXSignalNode(parent_id, NODE_LEAVE);
  245.     }
  246.     
  247.     ExecXSignalNode(base_id,   NODE_ENTER);
  248. }
  249.  
  250. void
  251. x_post_proc(node, state)
  252.     Plan node;            /* plan node */
  253.     BaseNode state;        /* node's private state */
  254. {
  255.     int      base_id =     get_base_id(state);
  256.     Plan     base_parent =     (Plan) get_base_parent(state);
  257.     BaseNode     parentstate;        
  258.     int      parent_id;
  259.  
  260.     /* ----------------
  261.      *    "leave" this node and "enter" the parent node
  262.      * ----------------
  263.      */
  264.     ExecXSignalNode(base_id,   NODE_LEAVE);
  265.  
  266.     if (base_parent != NULL) {
  267.     parentstate = (BaseNode) get_base_parent_state(state);
  268.     parent_id = get_base_id(parentstate);
  269.     ExecXSignalNode(parent_id, NODE_LEAVE);
  270.     }
  271. }
  272.   
  273. void
  274. x_pre_end(node, state)
  275.     Plan node;            /* plan node */
  276.     BaseNode state;        /* node's private state */
  277. {
  278. }
  279.  
  280. void
  281. x_post_end(node, state)
  282.     Plan node;            /* plan node */
  283.     BaseNode state;        /* node's private state */
  284. {
  285.     Plan base_parent =     (Plan) get_base_parent(state);
  286.  
  287.     /* ----------------
  288.      *    terminate the X process when we get all the way back
  289.      *  to the root of the tree..
  290.      * ----------------
  291.      */
  292.     if (base_parent == NULL)
  293.     ExecXTerminate();
  294. }
  295.  
  296. /* ----------------
  297.  *    InitXHook assigns the X hook routines to the given hook.
  298.  * ----------------
  299.  */
  300. void
  301. InitXHook(hook)
  302.     HookNode hook;
  303. {
  304.     set_hook_at_initnode(hook,   x_at_init);
  305.     set_hook_pre_procnode(hook,  x_pre_proc);
  306.     set_hook_pre_endnode(hook,   x_pre_end);
  307.     set_hook_post_initnode(hook, x_post_init);
  308.     set_hook_post_procnode(hook, x_post_proc);
  309.     set_hook_post_endnode(hook,  x_post_end);
  310. }
  311.